﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace WebApp
{
    public partial class Teacher : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.txtTNo.Text = ((Label)this.Master.FindControl("lblUserName")).Text;
        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            string strSql = "SELECT   TeaName, Gender, Class, Subject, Memo FROM      TeacherInfo  WHERE   (TeaNo = @TeaNo)";
            SqlParameter[] pms = new SqlParameter[1];
            pms[0] = new SqlParameter("@TeaNo", ((Label)this.Master.FindControl("lblUserName")).Text);
            SqlDataReader dr = SqlHelper.ExecuteReader(strSql, pms);
            if (dr.Read())
            {
                this.txtTName.Text = dr["TeaName"].ToString();
                this.txtTGender.Text = dr["Gender"].ToString();
                this.txtTClass.Text = dr["Class"].ToString();
                this.txtTsubject.Text = dr["Subject"].ToString();
                this.txtMemo.Text = dr["Memo"].ToString();
                ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('已成功查询！')", true);

            }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('查询失败！您尚未编辑您的个人基本信息！')", true);
            }
            dr.Close();

        }

        protected void btnUpdata_Click(object sender, EventArgs e)
        {
            try
            {

                StringBuilder SqlStringBuilder = new StringBuilder(1024);
                SqlStringBuilder.Append("UPDATE  TeacherInfo ");
                SqlStringBuilder.AppendFormat("SET     TeaName = N'{0}', Gender = N'{1}', Class = N'{2}', Subject = N'{3}', Memo = N'{4}' ", this.txtTName.Text, this.txtTGender.Text, this.txtTClass.Text, this.txtTsubject.Text, this.txtMemo.Text);
                SqlStringBuilder.AppendFormat("WHERE   (TeaNo = N'{0}') ", this.txtTNo.Text);

                int iUpd = SqlHelper.ExecuteNonQuery(SqlStringBuilder.ToString());
                if (iUpd > 0)
                {
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('更新成功！已更新" + iUpd.ToString() + "条记录！')", true);
                }
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = "更新失败！请重新编辑……具体原因：" + ex.Message;
            }
        }

        protected void btnSource_Click(object sender, EventArgs e)
        {
            string strSql = "SELECT  * FROM     TeacherInfo  WHERE   (TeaNo = @TeaNo)";
            SqlParameter[] pms = new SqlParameter[1];
            pms[0] = new SqlParameter("@TeaNo", ((Label)this.Master.FindControl("lblUserName")).Text);
            SqlDataReader dr = SqlHelper.ExecuteReader(strSql, pms);
            this.gvT.DataSource = dr;
            this.gvT.DataBind();

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

            Session["Theme"] = this.DropDownList1.SelectedValue.ToString();
        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["Theme"] != null)
                this.Theme = Session["Theme"].ToString();
        }

        
    }
}